/*
 * user.h
 *
 *  Created on: 2013. 7. 19.
 *      Author: jjaehuny
 */

#ifndef USER_H_
#define USER_H_

#include <Dispatcher/Static.h>
#include "../idl/Cache.h"
#include <functional>

#include <map>

namespace CacheServer {

class ChannelServer;

struct User : public ::Database::Command::IObserver
{
public:
	struct Character
	{
		bool _bOpen;
		bool _bLoad;	// DB에서 데이터가 로딩되면 true, 캐릭터 슬롯에만 할당된 상태이면 false
		uint32_t _char_seq;
		CharacterInfo _characterInfo;
	};

public:
	User();
	virtual ~User();

	virtual void OnResponse(::Database::Command * pCommand);
	virtual void OnError(::Database::Command * pCommand, const char* err, int errCode);
	void OnTime();

	UserInfo &		GetUserInfo();
	void 			SetUserInfo(UserInfo userInfo);

	void 	SetUserSeq(int userSeq);
	int 	GetUserSeq();

	void 	SetTimer();
	void	SetRandomTime();
	void 	KillTimer();

	void 	Initialize(int channelKey);
	int		GetChannelKey() { return _channelKey; }

	bool	GetKilledFlag() { return _bKilled; }

public:
	std::map<uint32_t, Character > _char_tree;

private:
	Dispatcher::Timer * _monitorTimer;
	UserInfo 			_userInfo;
	int 				_userSeq;
	bool				_bKilled;
	int					_channelKey;
};

} /* namespace cacheserver */
#endif /* USER_H_ */
